package com.zhuojy.equity.mall.admin.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.Document;
import com.zhuojy.equity.mall.admin.common.entity.DocumentClass;
import com.zhuojy.equity.mall.admin.dal.mapper.DocumentMapper;
import com.zhuojy.equity.mall.admin.manager.DemoManager;
import com.zhuojy.equity.mall.admin.manager.DocumentManager;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;

@Slf4j
@Service
@RequiredArgsConstructor
/**
 * 类型转换用
 */
public class DocumentService extends ServiceImpl<DocumentMapper,Document> {
    private  final DocumentManager documentManager;
    public IPage queryRecruitment(Document document, Integer pageNum, Integer pageSize) {
        IPage page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<Document> lambdaQueryWrapper = Wrappers.lambdaQuery();

        page = page(page,lambdaQueryWrapper);
        return page;
    }

    /**
     * 删除
     * @param id
     */
    public void deleteDocument(Integer id) {
        this.baseMapper.deleteById(id);
    }

    /**
     * 修改
     * @param
     * @param
     */
    public void updateDocument(Document document) {
        if (document.getId()!=null){
            Document document1 = new Document();
            document1=document;
            document1.setTurnoverTime(new Date());
            this.baseMapper.updateById(document1);
        }else{
            this.baseMapper.insert(document);
        }
    }

    /**
     * 分页查询
     * @param document
     * @return
     */
    public IPage queryRecruitment2(Document document) {
        IPage page = new Page<>(document.getCurrentPage(),document.getPageSize());
        LambdaQueryWrapper<Document> lambdaQueryWrapper = Wrappers.lambdaQuery();
        if(document.getTitle()!=null &&!document.getTitle().equals("")){
            lambdaQueryWrapper.like(Document::getTitle,document.getTitle());
        }
        if (document.getFromColumn()!=null){
            lambdaQueryWrapper.like(Document::getFromColumn,document.getFromColumn());
        }
        page = page(page,lambdaQueryWrapper);
        return page;
    }
}
